package tt.love.hw.common;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

import org.apache.tiles.TilesContainer;
import org.apache.tiles.access.TilesAccess;

public class ViewRender {

	private String path;

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public ViewRender(String path) {
		this.path = path;
	}

	@SuppressWarnings("deprecation")
	public void render(ActionContext actionContext) throws ServletException,
			IOException {
		if (path.startsWith("/") || path.endsWith(".jsp")) {
			RequestDispatcher rd = actionContext.getRequest()
					.getRequestDispatcher(path);
			rd.forward(actionContext.getRequest(), actionContext.getResponse());
		} else {
			TilesContainer container = TilesAccess.getContainer(actionContext
					.getRequest().getSession().getServletContext());
			container.render(path, actionContext.getRequest(), actionContext
					.getResponse());
		}

	}
}
